/**
 * @(#)ProvinceUtil.java 2017年8月22日
 * Copyright(C) 2017 ZHEXIN IT CO.,LTD. All rights reserved.
 */
package org.jsbd.boss.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 省份按量随机
 *
 * @author <a href="mailto:xupengcheng@zhexinit.com" >徐鹏程</a>
 * @version 1.0.0
 */
public class ProvinceUtil {

	private static Map<Integer, Double> provinceMap = new HashMap<Integer, Double>();
	private static Map<Double, Integer> rateMap = new HashMap<Double, Integer>();
	static {
		provinceMap.put(0, 4.59);
		provinceMap.put(1, 0.68);
		provinceMap.put(2, 0.96);
		provinceMap.put(3, 2.23);
		provinceMap.put(4, 1.83);
		provinceMap.put(5, 1.11);
		provinceMap.put(6, 2.12);
		provinceMap.put(7, 1.26);
		provinceMap.put(8, 0.26);
		provinceMap.put(9, 1.09);
		provinceMap.put(10, 0.63);
		provinceMap.put(11, 2.05);
		provinceMap.put(12, 3.45);
		provinceMap.put(13, 7.74);
		provinceMap.put(14, 8.49);
		provinceMap.put(15, 9.25);
		provinceMap.put(16, 0.09);
		provinceMap.put(17, 2.13);
		provinceMap.put(18, 4.86);
		provinceMap.put(19, 1.92);
		provinceMap.put(20, 3.17);
		provinceMap.put(21, 10.81);
		provinceMap.put(22, 2.84);
		provinceMap.put(23, 4.34);
		provinceMap.put(24, 3.02);
		provinceMap.put(25, 3.16);
		provinceMap.put(26, 5.07);
		provinceMap.put(27, 7.10);
		provinceMap.put(28, 2.99);
		provinceMap.put(29, 0.18);
		provinceMap.put(30, 0.56);

		rateMap.put(4.59, 0);
		rateMap.put(0.68, 1);
		rateMap.put(0.96, 2);
		rateMap.put(2.23, 3);
		rateMap.put(1.83, 4);
		rateMap.put(1.11, 5);
		rateMap.put(2.12, 6);
		rateMap.put(1.26, 7);
		rateMap.put(0.26, 8);
		rateMap.put(1.09, 9);
		rateMap.put(0.63, 10);
		rateMap.put(2.05, 11);
		rateMap.put(3.45, 12);
		rateMap.put(7.74, 13);
		rateMap.put(8.49, 14);
		rateMap.put(9.25, 15);
		rateMap.put(0.09, 16);
		rateMap.put(2.13, 17);
		rateMap.put(4.86, 18);
		rateMap.put(1.92, 19);
		rateMap.put(3.17, 20);
		rateMap.put(10.81, 21);
		rateMap.put(2.84, 22);
		rateMap.put(4.34, 23);
		rateMap.put(3.02, 24);
		rateMap.put(3.16, 25);
		rateMap.put(5.07, 26);
		rateMap.put(7.10, 27);
		rateMap.put(2.99, 28);
		rateMap.put(0.18, 29);
		rateMap.put(0.56, 30);
	}

	public static Integer[] randomProvinces(Integer[] provinces) {
		Integer[] targetProvinces = null;
		List<Double> list = new ArrayList<Double>();
		if (provinces != null && provinces.length > 0) {
			targetProvinces = new Integer[provinces.length];
			for (Integer province : provinces) {
				list.add(provinceMap.get(province));
			}
		}
		for (int i = 0; i < provinces.length; i++) {
			int index = NumUtil.randomChoiceIndex2(list);
			targetProvinces[i] = rateMap.get(list.get(index));
			list.remove(index);
		}
		return targetProvinces;
	}

}
